//
//  CZServiceLogController.m
//  TCProject
//
//  Created by admin on 16/1/25.
//  Copyright © 2016年 wise-wing. All rights reserved.
//

#import "CZServiceLogController.h"
#import "CZServiceLogCell.h"
#import "AccountManager.h"
#import "CZServiceLogInfoController.h"


@interface CZServiceLogController ()

@end

@implementation CZServiceLogController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"服务详情";
    
    self.view.backgroundColor = BMColor(245, 245, 245, 247);
    self.tableView.contentInset = UIEdgeInsetsMake(10, 0, 0, 0);
    self.tableView.rowHeight = UITableViewAutomaticDimension;
    self.tableView.estimatedRowHeight = 150.f;
    [self.tableView registerNib:[UINib nibWithNibName:@"CZServiceLogCell" bundle:nil] forCellReuseIdentifier:reuseIdentifier];
    self.tableView.separatorStyle= UITableViewCellSeparatorStyleNone;
}



#pragma mark - Table view data source


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

        return _order.serviceLogs.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    CZServiceLogCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
    cell.log = _order.serviceLogs[(NSUInteger) indexPath.row];
    cell.editOperation = ^{
        CZServiceLogInfoController *infoVC = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"logInfoVC"];
        infoVC.order = _order;
        infoVC.log = _order.serviceLogs[(NSUInteger) indexPath.row];
        [self showViewController:infoVC sender:nil];
    };
    return cell;

}

- (void)updateServiceLog
{
    BMRequest *request = [BMRequest requestWithPath:@"getMyServices.htm" contentKey:@"serviceLogs"];
    request.params = @{@"ownerId": @([AccountManager sharedInstance].user.ID), @"orderId": @(_order.ID),  @"pageNo": @1, @"pageSize": @100000};
    [ServiceLog postWithRequest:request finish:^(BMResponse *response, NSError *error) {
        if (response.status == kResultOK) {
            _order.serviceLogs = response.result;
            [self.tableView reloadData];
        } else if (response.status == 2) {
            [self showHint:@"暂无服务记录"];
        } else {
            [self showHint:@"获取服务记录失败"];
        }
    }];
}

@end
